// NumberDraw.cpp: implementation of the CNumberDraw class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "NumberDraw.h"

#include "Global.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CNumberDraw::CNumberDraw()
{
	SetPlane(&PlaneNumber1);
}

CNumberDraw::~CNumberDraw()
{

}

void CNumberDraw::SetPlane(CD3DPlane *pplane)
{
	pPlane = pplane;
}

void CNumberDraw::Draw(int xp, int yp, int number, DRAWDESC desc)
{
	CString str;
	str.Format("%d", number);
	Draw(xp, yp, str, desc);
}

void CNumberDraw::Draw(int xp, int yp, CString& str, DRAWDESC desc)
{
	//CD3DPlane *pPlane = &PlaneNumber1;
	if(pPlane->IsWrongSpr(0)) return;
	
	float w = (float)pPlane->m_pInfo[0].xl * desc.fXScale;
	float h = (float)pPlane->m_pInfo[0].yl * desc.fYScale;

	int slen = str.GetLength();

	float x = (float)xp;
	float y = (float)yp;

	float totw = slen * w;

	if((desc.dwFlag & _CENTER)) {
		x -= totw/2;
		y -= h/2;
		desc.dwFlag ^= _CENTER;
	}

	for(int i=0; i<slen; i++) {
		char c = str.GetAt(i);
		int spn = c - '0';
		if(c == '+') spn = 10;
		else if(c == '-') spn = 11;
		if(spn<0 || spn > 11) continue;
		pPlane->DrawPlane(x, y, spn, &desc);
		x += w;
	}
}